#!/bin/sh
#
# Enable/disable persistent logging based on config.json settings.
#

set -e

. /usr/libexec/os-helpers-logging
. /usr/sbin/balena-config-vars

if [ "$PERSISTENT_LOGGING" = "true" ] && [ ! -d /var/log/journal ]; then
    mkdir -p /var/log/journal
    systemctl start bind-var-log-journal.service
    journalctl --flush
    info "Persistent logging activated."
elif [ "$PERSISTENT_LOGGING" = "true" ] && [ -d /var/log/journal ]; then
    info "Persistent logging already activated."
    journalctl --flush
elif [ "$PERSISTENT_LOGGING" = "false" ] && [ -d /var/log/journal ]; then
    info "Persistent logging was deactivated but system reboot is needed."
else
    info "Persistent logging deactivated."
fi
